<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <title>光速洗车</title>
</head>
<body>

<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 光速洗车
    <span class="c-gray en">&gt;</span> 活动配置
</nav>
<div class="page-container">
    <div id="platformAutoActivityToolbar">
        <!--
        <a href="javascript:;" onclick="platformMerchantAutoActivityFun.datadel()" class="btn btn-danger radius">
            <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
        </a>
        <a class="btn btn-primary radius" href="javascript:;"
           data-toggle="modal"
           data-target="#autoActivityAddmodal"
           onclick="platformMerchantAutoActivityFun.autoActivityAddclick()">
            <i class="Hui-iconfont">&#xe600;</i> 添加活动
        </a>
        -->
    </div>
    <div>
        <table id="autoActivitytable" class="table table-border table-bordered table-bg table-hover table-sort">
        </table>
    </div>
</div>
<!--******************增加活动模态框****************-->
<div class="modal fade autoActivityAddmodal" tabindex="-1" role="dialog" id="autoActivityAddmodal">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title activityAddEdit">增加</h4>
            </div>
            <div class="modal-body">
                <form action="" method="post" class="form form-horizontal" id="autoActivity-form">
                    <input style="display: none;" id="autoActivity-activityId" name="activityId"/>
                    <div class="form-group">
                        <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>活动名称：</label>
                        <div class="formControls col-xs-4 col-sm-4">
                            <input type="text" class="form-control" value="" placeholder="必填项"
                                   id="autoActivity-activityName" name="activityName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>活动标题：</label>
                        <div class="formControls col-xs-4 col-sm-4">
                            <input type="text" class="form-control" value="" placeholder="必填项"
                                   id="autoActivity-activityTitle" name="activityTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>活动内容：</label>
                        <div class="formControls col-xs-4 col-sm-4">
                            <input type="text" class="form-control" value="" placeholder="必填项"
                                   id="autoActivity-activityContent" name="activityContent">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>开始时间：</label>
                        <div class="formControls col-xs-4 col-sm-4">
                            <input id="autoActivity-startTime" name="startTimes" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly" class="form-control Wdate" style="width:270px;">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-4 col-sm-3"><span class="c-red"></span>结束时间：</label>
                        <div class="formControls col-xs-4 col-sm-4">
                            <input id="autoActivity-endTime" name="endTimes" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly="readonly" class="form-control Wdate" style="width:270px;">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button onclick="platformMerchantAutoActivityFun.autoActivityAddSubmit()" type="button" class="btn btn-primary">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>

        </div>
    </div>
</div>
<script type="text/javascript">
    /*活动管理 platformMerchantAutoActivityFun*/
    var platformMerchantAutoActivityFun;

    platformMerchantAutoActivityFun = {
        init : function () {
            let _this = this;
            _this.bootstrapvalidatorForm();
            //活动管理展示所有
            $('#autoActivitytable').bootstrapTable({
                url: 'mkt/getAllMktActivities',         //请求后台的URL（*）
                method: 'get',
                toolbar: '#platformAutoActivityToolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                //search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                // height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [
                    {
                        checkbox: true
                    }, {
                        field: 'bizId',
                        title: '商户id',
                        visible:false
                    }, {
                        field: 'activityName',
                        title: '活动名称'
                    }, {
                        field: 'activityTitle',
                        title: '活动标题'
                    }, {
                        field: 'activityContent',
                        title: '活动内容'
                    }, {
                        field: 'activityState',
                        title: '活动状态',
                        formatter:function(value,row,index) {
                            if (value == '0') {
                                return '禁用';
                            } else {
                                return '启用';
                            }
                        }
                    }, {
                        field: 'startTime',
                        title: '开始时间'
                    }, {
                        field: 'endTime',
                        title: '结束时间'
                    }, {
                        field: 'addTime',
                        title: '创建时间'
                    }, {
                        field: 'address',
                        title: '操作',
                        formatter : function (value, row,index) {
                            return `
                                    <a class="btn btn-danger btn-sm" type="button"
                                        onclick="platformMerchantAutoActivityFun.close_array('${row.activityId}','${row.activityState}')">禁用</a>
                                    <a class="btn btn-success btn-sm" type="button"
                                        onclick="platformMerchantAutoActivityFun.open_array('${row.activityId}','${row.activityState}')">启用</a>
                                    <a class="btn btn-info btn-sm" href="javascript:;"
                                       onclick="platformMerchantAutoActivityFun.updateAutoActivity('${row.activityId}')">修改</a>
                                    </a>
                                   <!--<a class="btn btn-danger btn-sm" onclick="platformMerchantAutoActivityFun.del_array('${row.activityId}')"  >删除 </a> -->`
                        }
                    }
                ]
            });
        },
        //点击增加，清空文本框
        autoActivityAddclick : function () {
            $('.activityAddEdit').html('添加')
//            $('#autoService-bizShopPackage').val("");
//            $("#autowashName").val("");
//            $("#autowashPrice").val("");


            //重置validator
            $("#autoActivity-form").data('bootstrapValidator').resetForm();
        },
        //编辑活动数据渲染
        updateAutoActivity:function(id){
            //查寻单条数据
            $.ajax({
                type: "get",
                url: "mkt/getActivityByOne",
                data:{activityId:id},
                dataType: "json",
                success : function(data) {
                    if(data.state){
                        $("#autoActivity-activityId").val(data.data.activityId);
                        $("#autoActivity-activityName").val(data.data.activityName);
                        $("#autoActivity-activityTitle").val(data.data.activityTitle);
                        $("#autoActivity-activityContent").val(data.data.activityContent);
                        $("#autoActivity-startTime").val(data.data.startTime);
                        $("#autoActivity-endTime").val(data.data.endTime);

                    }else {
                        layer.msg("批量删除失败！", {icon: 2});
                        return false;
                    }

                },
                error:function () {
                    alert("error");
                }
            });

            $('.activityAddEdit').html('编辑');
            $('#autoActivityAddmodal').modal("show");
        },
        //增加活动提交
        autoActivityAddSubmit : function () {
            let _this = this;
            //bootstrap验证
            var bootstrapValidator = $("#autoActivity-form").data('bootstrapValidator');
            bootstrapValidator.validate();
            if(bootstrapValidator.isValid())
                //保存
                $.ajax({
                    type: "get",
                    url: "mkt/updateActivityById",
                    data:$("#autoActivity-form").serialize(),
                    dataType: "json",
                    success : function(data) {
                        if(data.state){
                            layer.msg(data.message, {icon: 1});

                            //涮新一次
                            $("#autoActivitytable").bootstrapTable("refresh");
                            $("#autoActivityAddmodal").modal('hide');
                            return true;
                        }else {
                            layer.msg("修改失败！", {icon: 2});
                            return false;
                        }

                    },
                    error:function () {
                        alert("error");
                    }
                });

            else return;

        },
        //批量删除
        datadel : function () {
            let _this = this;
            layer.confirm('确认要删除吗？',
                {
                    btn: ['确定','取消']
                },
                function(){
                    //确认删除
                    //获取所有被选中的记录
                    var rows = $("#autoActivitytable").bootstrapTable('getSelections');
                    if (rows.length== 0) {
                        layer.alert("请先选择要删除的记录!");
                        return;
                    }
                    var ids = '';
                    for (var i = 0; i < rows.length; i++) {
                        ids += rows[i]['bizId'] + ",";
                    }
                    ids = ids.substring(0, ids.length - 1);

                    //删除
                    $.ajax({
                        type: "get",
                        url: "biz/deleteMoreBizTenant",
                        data:{listId:ids},
                        dataType: "json",
                        success : function(data) {
                            if(data.state){
                                layer.msg(data.message, {icon: 1});
                                //涮新一次
                                _this.searchAction();

                                return true;
                            }else {
                                layer.msg("批量删除失败！", {icon: 2});
                                return false;
                            }

                        },
                        error:function () {
                            alert("error");
                        }
                    });

                },
                function(){
                    layer.msg('已取消！', {icon: 1});
                    return false;
                }
            );
        },
        //按条件筛选查询
        searchAction : function () {
            var addTimes = $("#logmin").val();
            var bizName = $("#bizNameSearch").val();
            var address = $("#addressSearch").val();
            //商户管理，条件查询
            $.ajax({
                type: "get",
                url: "biz/getAllBizTenant",
                data:{addTimes:addTimes,bizName:bizName,address:address},
                dataType: "json",
                success : function(json) {
                    $("#autoActivitytable").bootstrapTable('load', json);
                },
                error:function () {
                    alert("error");
                }
            });
        },
        //启用活动
        open_array: function (index, state) {
            //判断该活动是否已经处于启用
            if (state == 1) {
                layer.msg("该活动已经处于启用状态！", {icon: 0});
                return;
            }
            $.ajax({
                type: "get",
                url: "mkt/mktActivitiesEnable",
                data: {activityId: index},
                dataType: "json",
                success: function (data) {
                    //state为true，启用成功
                    if (data.state) {
                        layer.msg(data.message, {icon: 1});

                        //涮新table
                        $("#autoActivitytable").bootstrapTable("refresh");

                        return true;
                    } else {
                        layer.msg("启用失败！", {icon: 2});
                        return false;
                    }
                },
                error: function () {
                    layer.msg('错误！', {icon: 2});
                    return false;
                }
            });
        },
        //禁用活动
        close_array: function (index, state) {
            //判断该活动是否已经处于禁用
            if (state == 0) {
                layer.msg("该活动已经处于禁用状态！", {icon: 0});
                return;
            }
            //禁用
            $.ajax({
                type: "get",
                url: "mkt/mktActivitiesDisEnable",
                data: {activityId: index},
                dataType: "json",
                success: function (data) {
                    //state为true，禁用成功
                    if (data.state) {
                        layer.msg(data.message, {icon: 1});

                        //涮新table
                        $("#autoActivitytable").bootstrapTable("refresh");

                        return true;
                    } else {
                        layer.msg("禁用失败！", {icon: 2});
                        return false;
                    }
                },
                error: function () {
                    layer.msg('错误！', {icon: 2});
                    return false;
                }
            });
        },
        //点击单个删除按钮
        del_array : function  (index){
            let _this = this;
            layer.confirm('确认要删除吗？',
                {
                    btn: ['确定','取消']
                },
                function(){
                    //确认删除
                    $.ajax({
                        type: "get",
                        url: "biz/deleteBizTenant",
                        data:{bizId:index},
                        dataType: "json",
                        success : function(data) {
                            if(data.state){
                                layer.msg(data.message, {icon: 1});
                                //涮新一次
                                _this.searchAction();

                                return true;
                            }else {
                                layer.msg("删除失败！", {icon: 2});
                                return false;
                            }
                        },
                        error:function () {
                            layer.msg('错误！', {icon: 2});
                            return false;
                        }
                    });

                },
                function(){
                    layer.msg('已取消！', {icon: 1});
                    return false;
                }
            );

        },
        //bootstrap验证
        bootstrapvalidatorForm: function () {

            $('#autoActivity-form').bootstrapValidator({
                message: 'This value is not valid',
                excluded : [':disabled'],
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    activityName: {
                        validators: {
                            notEmpty: {
                                message: '活动名称不能为空'
                            },
                            stringLength: {
                                min: 2,
                                max: 100,
                                message: '服务名称长度必须在2到100位之间'
                            }
                        }
                    },
                    activityTitle: {
                        validators: {
                            notEmpty: {
                                message: '活动标题不能为空'
                            }
                        }
                    },
                    activityContent: {
                        validators: {
                            notEmpty: {
                                message: '活动内容不能为空'
                            }
                        }
                    },
                    startTimes: {
                        validators: {
                            notEmpty: {
                                message: '开始时间不能为空'
                            }
                        }
                    },
                    endTimes: {
                        validators: {
                            notEmpty: {
                                message: '结束时间不能为空'
                            }
                        }
                    }
                }
            });
        }
    };

    platformMerchantAutoActivityFun.init();
</script>
</body>
</html>